
#pragma once

#include "type.h"
#include "gameaction.h"

#include <string>

struct EquipmentAttribute {
	std::string name;
	std::string desc;

	vector<EquipmentAction> actions;

	int id;

	EquipmentType type;
	EquipmentRarity rarity;
	EquipmentGenre genre;

	AttackType attackType;
	BulletProjectileType projectileType;
	EquipmentEffectType effectType;

	int points;
	int defense;
	int range;
	int splashCases;

	int castingTime;
	int reloadTime;

	int slashAttack;
	int bluntAttack;
	int piercingAttack;
	int explosionAttack;
	int fireAttack;
	int iceAttack;
	int poisonAttack;
	int thunderAttack;
	int darkAttack;
	int holyAttack;

	int slashResist;
	int bluntResist;
	int piercingResist;
	int explosionResist;
	int fireResist;
	int iceResist;
	int poisonResist;
	int thunderResist;
	int darkResist;
	int holyResist;

	int dummy;

	EquipmentAttribute() {
		memset(&(this->id), 0, (&(this->dummy) - &(this->id)) * sizeof(int));
	}

	static EquipmentType parseType(const char * s) {
		EquipmentType ret = EquipmentType::creature;

		for(int i = 0; i < (int)EquipmentType::count; i++) {
			if(s && strcmp(EQUIPMENT_TYPE_NAMES[i], s) == 0) {
				ret = static_cast<EquipmentType>(i);
				break;
			}
		}

		return ret;
	}

	static EquipmentRarity parseRarity(const char * s) {
		EquipmentRarity ret = EquipmentRarity::common;

		for(int i = 0; i < (int)EquipmentRarity::count ; i++) {
			if(s && strcmp(RARITY_NAMES[i], s) == 0) {
				ret = static_cast<EquipmentRarity>(i);
				break;
			}
		}

		return ret;
	}

	static EquipmentGenre parseGenre(const char* s) {
		EquipmentGenre ret = EquipmentGenre::creature_human;

		for(int i = 0; i < (int)EquipmentGenre::count ; i++) {
			if(s && strcmp(EQUIPMENT_GENRE_NAMES[i], s) == 0) {
				ret = static_cast<EquipmentGenre>(i);
				break;
			}
		}

		return ret;
	}

	static AttackType parseAttackType(const char* s) {
		AttackType ret = AttackType::none;

		for(int i = 0; i < (int)AttackType::count ; i++) {
			if(s && strcmp(ATTACK_TYPE_NAMES[i], s) == 0) {
				ret = static_cast<AttackType>(i);
				break;
			}
		}

		return ret;
	}

	static BulletProjectileType parseBulletProjectileType(const char* s) {
		BulletProjectileType ret = BulletProjectileType::none;

		for(int i = 0; i < (int)BulletProjectileType::count ; i++) {
			if(s && strcmp(BULLET_PROJECTILE_TYPE_NAMES[i], s) == 0) {
				ret = static_cast<BulletProjectileType>(i);
				break;
			}
		}

		return ret;
	}

	static EquipmentEffectType parseEquipmentEffectType(const char* s) {
		EquipmentEffectType ret = EquipmentEffectType::none;

		for(int i = 0; i < (int)EquipmentEffectType::count ; i++) {
			if(s && strcmp(EQUIPMENT_EFFECT_TYPE_NAMES[i], s) == 0) {
				ret = static_cast<EquipmentEffectType>(i);
				break;
			}
		}

		return ret;
	}
	
	int getTotalAttack(const EquipmentAttribute* resist = nullptr) const;
};
